package com.hsj.config;



import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Configuration
public class GetFileNamesConfig {
     //   在springboot 启动时，将 /data下所有文件名放入list
    @Bean
    public List<String> fileNameList() throws IOException {
        ArrayList<String> fileNameList = new ArrayList<>();
        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        Resource[] resources = resolver.getResources("classpath:" + "/data/*.*");
        for (Resource resource : resources) {
            String filename = resource.getFilename();
            fileNameList.add(filename);
        }
        return fileNameList;
    }

}
